﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTCementStrengthService : ServiceHandle, IRPTCementStrength
    {
        #region IRPTCementStrength Members

        public OperationResult<List<tb_RPT_CementStrength>> GetAllCementStrength()
        {
            OperationResult<List<tb_RPT_CementStrength>> result = new OperationResult<List<tb_RPT_CementStrength>>();
            List<tb_RPT_CementStrength> list = new List<tb_RPT_CementStrength>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllCementStrength();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_CementStrength>> GetCementStrengthByContition(string strTestDate, string strCementManufacturer,
                                                                                        string strCementLabel, string strAshManufacturer, string strQuickSide, string str3DStrength,
                                                                                        string str7DStrength, string str7DIndex, string str28DStrength,
                                                                                        string str28DIndex, string strStatistician)
        {
            OperationResult<List<tb_RPT_CementStrength>> result = new OperationResult<List<tb_RPT_CementStrength>>();
            List<tb_RPT_CementStrength> list = new List<tb_RPT_CementStrength>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetCementStrengthByContition(strTestDate, strCementManufacturer,
                                                              strCementLabel, strAshManufacturer, strQuickSide, str3DStrength,
                                                              str7DStrength, str7DIndex, str28DStrength,
                                                              str28DIndex, strStatistician);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_CementStrength> GetCementStrengthById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_CementStrength> result = new OperationResult<tb_RPT_CementStrength>();
            tb_RPT_CementStrength cementStrength;
            try
            {
                cementStrength = dataContext.GetCementStrengthById(id);
                if (cementStrength == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = cementStrength;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_CementStrength> CreateCementStrength(tb_RPT_CementStrength entity)
        {
            OperationResult<tb_RPT_CementStrength> result = new OperationResult<tb_RPT_CementStrength>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateCementStrength(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_CementStrength> ModifyCementStrength(tb_RPT_CementStrength entity)
        {
            OperationResult<tb_RPT_CementStrength> result = new OperationResult<tb_RPT_CementStrength>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyCementStrength(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_CementStrength> DeleteCementStrength(tb_RPT_CementStrength entity)
        {
            OperationResult<tb_RPT_CementStrength> result = new OperationResult<tb_RPT_CementStrength>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteCementStrength(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
